import time,calendar


def time_m1():
    #时间戳单位最适于做日期运算
    timest=time.time()
    print("当前时间戳为:", timest)

    t1=time.ctime()
    print("类型 = ",type(t1),t1)

    # 返回一个时间元组
    localtime = time.localtime(timest)
    print(f'type= {type(localtime)}本地时间为 :{localtime} \n {localtime.tm_year}/{localtime.tm_mon}/{localtime.tm_mday}')

    print("---"*6**2)
    print("ctime =",time.ctime())
    print("gmtime",time.gmtime())
    print("localtime",time.localtime())

    print("---" * 6 ** 2)

    # time.mktime
    t = (2016, 2, 17, 17, 3, 38, 1, 48, 0)
    secs = time.mktime(t)
    print("time.mktime(t) : %f" % secs)
    secs=time.mktime(time.gmtime())
    print("time.mktime(t) : %f" % secs)
    print("asctime(localtime(secs)): %s" % time.asctime(time.localtime(secs)))

    localtime = time.asctime(time.localtime(time.time()))
    print("本地时间为 :", localtime)

    # 格式化成2016-03-20 11:45:39形式
    print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))

    # 格式化成Sat Mar 28 22:24:24 2016形式
    print(time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()))

    # 将格式字符串转换为时间戳
    a = "Sat Mar 28 22:24:24 2016"
    print(time.mktime(time.strptime(a, "%a %b %d %H:%M:%S %Y")))

def calendar_m1():
    # 获取某月日历
    cal = calendar.month(2022, 1)
    print("type=",type(cal))
    print("以下输出2016年1月份的日历:\n",cal)

    #返回两个整数。第一个是该月第一天是星期几，第二个是该月有多少天。星期几是从0（星期一）到 6（星期日
    print(calendar.monthrange(2022, 11))

    print(calendar.firstweekday())

if __name__ == '__main__':
    time_m1()
    calendar_m1()